# -*- coding: utf-8 -*- 

import wx
import wx.xrc

###########################################################################
## Class CountPanel
###########################################################################

class CountPanel ( wx.Panel ):
    
    def __init__( self, parent ):
        wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.TAB_TRAVERSAL )
        
        bSizer31 = wx.BoxSizer( wx.VERTICAL )
        
        fgSizer3 = wx.FlexGridSizer( 0, 4, 0, 0 )
        fgSizer3.AddGrowableCol( 1 )
        fgSizer3.AddGrowableCol( 3 )
        fgSizer3.SetFlexibleDirection( wx.BOTH )
        fgSizer3.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
        
        self.m_staticText27 = wx.StaticText( self, wx.ID_ANY, u"首件生产时间：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText27.Wrap( -1 )
        fgSizer3.Add( self.m_staticText27, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcFirstTime = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY|wx.TE_RIGHT )
        fgSizer3.Add( self.m_tcFirstTime, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText30 = wx.StaticText( self, wx.ID_ANY, u"最后一件生产时间：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText30.Wrap( -1 )
        fgSizer3.Add( self.m_staticText30, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcLastTime = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY|wx.TE_RIGHT )
        fgSizer3.Add( self.m_tcLastTime, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText28 = wx.StaticText( self, wx.ID_ANY, u"合格数量：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText28.Wrap( -1 )
        self.m_staticText28.SetFont( wx.Font( 16, 70, 90, 92, False, wx.EmptyString ) )
        self.m_staticText28.SetForegroundColour( wx.Colour( 0, 187, 0 ) )
        
        fgSizer3.Add( self.m_staticText28, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, 5 )
        
        self.m_tcOKCount = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 120,-1 ), wx.TE_READONLY|wx.TE_RIGHT )
        self.m_tcOKCount.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
        self.m_tcOKCount.SetBackgroundColour( wx.Colour( 149, 255, 149 ) )
        
        fgSizer3.Add( self.m_tcOKCount, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText29 = wx.StaticText( self, wx.ID_ANY, u"不合格数量：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText29.Wrap( -1 )
        self.m_staticText29.SetFont( wx.Font( 14, 70, 90, 92, False, wx.EmptyString ) )
        self.m_staticText29.SetForegroundColour( wx.Colour( 255, 0, 0 ) )
        
        fgSizer3.Add( self.m_staticText29, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcNOKCount = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 120,-1 ), wx.TE_RIGHT )
        self.m_tcNOKCount.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
        self.m_tcNOKCount.SetBackgroundColour( wx.Colour( 255, 176, 176 ) )
        
        fgSizer3.Add( self.m_tcNOKCount, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText31 = wx.StaticText( self, wx.ID_ANY, u"生产总数：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText31.Wrap( -1 )
        fgSizer3.Add( self.m_staticText31, 0, wx.ALL, 5 )
        
        self.m_tcTotalCount = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY|wx.TE_RIGHT )
        fgSizer3.Add( self.m_tcTotalCount, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText32 = wx.StaticText( self, wx.ID_ANY, u"耗时：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText32.Wrap( -1 )
        fgSizer3.Add( self.m_staticText32, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcTotalTime = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY|wx.TE_RIGHT )
        fgSizer3.Add( self.m_tcTotalTime, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText33 = wx.StaticText( self, wx.ID_ANY, u"合格率：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText33.Wrap( -1 )
        fgSizer3.Add( self.m_staticText33, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcFTQ = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        fgSizer3.Add( self.m_tcFTQ, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_staticText34 = wx.StaticText( self, wx.ID_ANY, u"生产效率：", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText34.Wrap( -1 )
        fgSizer3.Add( self.m_staticText34, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_tcEfficiency = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        fgSizer3.Add( self.m_tcEfficiency, 0, wx.ALL|wx.EXPAND, 5 )
        
        bSizer31.Add( fgSizer3, 1, wx.EXPAND, 5 )
        
        self.SetSizer( bSizer31 )
        self.Layout()
        bSizer31.Fit( self )
        
    def Set(self, okcnt, nokcnt, firsttime, lasttime):
        self.m_tcOKCount.SetValue(u"%d" % okcnt)
        self.m_tcNOKCount.SetValue(u"%d" % nokcnt)
        self.m_tcFirstTime.SetValue(firsttime.strftime("%Y-%m-%d %H:%M:%S"))
        self.m_tcLastTime.SetValue(lasttime.strftime("%Y-%m-%d %H:%M:%S"))
        self.m_tcTotalCount.SetValue(u"%d" % (okcnt + nokcnt))
        ti = lasttime - firsttime
        self.m_tcTotalTime.SetValue(u"%.3f 小时" % (float(ti.total_seconds())/3600.0))
        self.m_tcFTQ.SetValue(u"%.2f%%" % (float(okcnt)/float(okcnt + nokcnt)*100.0))
        if ti.total_seconds() != 0:
            self.m_tcEfficiency.SetValue(u"%.3f 件/小时" % (float(okcnt + nokcnt)/(float(ti.total_seconds())/3600.0)))
    
    def Clear(self):
        self.m_tcFirstTime.SetValue(u"")
        self.m_tcLastTime.SetValue(u"")
        self.m_tcFTQ.SetValue(u"")
        self.m_tcEfficiency.SetValue(u"")
        self.m_tcOKCount.SetValue(u"0")
        self.m_tcNOKCount.SetValue(u"0")
        self.m_tcTotalCount.SetValue(u"0")
        self.m_tcTotalTime.SetValue(u"")